<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <user-card :user="user" />
        </el-col>

        <el-col :span="12" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="活动" name="activity">
                <activity />
              </el-tab-pane>
              <el-tab-pane label="时间线" name="timeline">
                <timeline />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

        <el-col :span="6" :xs="24">
          <el-card>
            <el-tabs v-model="tabPaneName" tab-position="top">
              <el-tab-pane label="更新资料" name="profile">
                <ProfileIndex :user="user" />
              </el-tab-pane>
              <el-tab-pane label="更改密码" name="account">
                <account :user="user" />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/UserCard'
import Activity from './components/Activity'
import Timeline from './components/Timeline'
import Account from './components/Account'
import ProfileIndex from './components/ProfileIndex'
import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:9090'

export default {
  name: 'Profile',
  components: { UserCard, Activity, Timeline, Account, ProfileIndex },
  data() {
    return {
      // user: {},
      activeTab: 'activity',
      tabPaneName: 'profile'
    }
  },
  computed: {
    ...mapGetters([
      'token',
      'name',
      'avatar',
      'profile'
      // 'roles'
    ]),
    user() {
      return {
        name: this.name,
        avatar: this.avatar,
        // role: this.roles.join(' | '),

        username: this.profile?.username || '',
        headUrl: this.profile?.headUrl || '',
        status: this.profile?.status || 1,
        roleName: this.profile?.roleName || '普通用户',
        deptName: '',
        postName: '',
        phone: this.profile?.phone || '',
        email: this.profile?.email || '',
        description: this.profile?.description || ''
      };
    }
  },
  // created() {
  //   this.getUser()
  // },
  // methods: {
  //   getUser() {
  //     this.user = {
  //       username: this.profile.username,
  //       name: this.name,
  //       // role: this.roles.join(' | '),
  //       avatar: this.avatar,

  //       headUrl: this.profile.headUrl,
  //       status: this.profile.status,
  //       roleName: '普通用户',
  //       deptName: '',
  //       postName: '',
  //       phone: this.profile.phone,
  //       email: this.profile.email,
  //       description: this.profile.description,
  //     }
  //   }
  // }
}
</script>
